package cn.wolfcode.qo;

import cn.wolfcode.domain.Department;
import cn.wolfcode.mapper.DepartmentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Getter
public class PageResult<T> {
    private int currentPage=1;
    private int pageSize;
    private int totalCount;
    private List<T> data;

    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        //计算总页数   上一页  下一页
        if(totalCount <= pageSize) {
            this.totalPage = 1;
            this.currentPage = 1;
            this.nextPage = 1;
            this.prevPage = 1;
            return;
        }

        this.totalPage = this.totalCount % this.pageSize == 0?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize+1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ?
                this.currentPage + 1 : this.totalPage;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
    }


}
